/*
 * @Author       : liumour @3d3-Studio
 * @Date         : 2021-02-01 20:45:38
 * @LastEditTime : 2021-03-02 00:01:40
 * @----------------------------------
 * @FilePath     : \Pro_Ui\src\pages\manage\input.js
 * @Description  : 
 */
// 导入基础库
import { connect } from 'umi';
// 导入配置参数
import df from '../../../config/dataFormat';
// 导入处理函数
import com from '../../utils/common';
// 导入UI组件
import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
import ProForm from '@ant-design/pro-form';
import ff from './input_component/form_fields';
// 导入LESS样式
import styles from './input.less';

const PageView = (props) => {
  // 初始化参数------------------------------------------------
  const { ui, table: tb, socketio, dispatch: dp } = props;

  // 获取表单项
  const get_items = () => {
    const items = [];
    for (let i = 0; i < df.keys.length; i += 3) {
      var cit = [];
      for (let ci = 0; ci < 3; ci++) {
        var ik = df.keys[ci + i];
        var it = df.data_type[ik];
        if(it) cit.push(ff[it.type](ik, it.required, it.defVal,328));
      }
      items.push(
        <ProForm.Group key={i} className={styles.form_group}>
          {cit}
        </ProForm.Group>,
      );
    }
    return items;
  };

  // 事件处理函数
  const onFinish = (values) => {
    var put = {};
    df.keys.forEach((k) => (put[k] = null));
    var val = { ...put, ...values };
    val['数据来源'] = `${val['数据来源']?val['数据来源']:'其他'} ${com.get_format_date()} 由 ${
      tb.user.user
    } 录入`;
    val['操作记录'] = `${com.get_format_date()} 由 ${tb.user.name} 录入`;
    dp({
      type: 'socketio/emit',
      payload: { type: 'save_profile', data: [val] },
    });
  };

  // 渲染UI组件------------------------------------------------
  return (
    <PageContainer fixedHeader affixProps={{ offsetTop: 48 }}>
      <ProForm
        submitter={{
          searchConfig: {
            submitText: '录入数据',
            resetText: '清空表单',
          },
          render: (_, dom) => <FooterToolbar>{dom}</FooterToolbar>,
        }}
        onFinish={onFinish}
        initialValues={{
          是否到达玉林:'待核查',
          '本市人员/市外人员':'待核查',
          是否下发乡镇跟进:'待处理',
          管控状态:'待核查'
        }}
      >
        {get_items()}
      </ProForm>
    </PageContainer>
  );
};

export default connect(({ ui, table, socketio }) => ({ ui, table, socketio }))(
  PageView,
);
